//
//  AccountViewController.m
//  dyseller
//
//  Created by 红喇叭 on 2017/8/18.
//  Copyright © 2017年 红喇叭. All rights reserved.
//

#import "AccountViewController.h"
#import "AccountCell.h"

@interface AccountViewController ()<UITableViewDelegate,UITableViewDataSource>{
    NSArray *_todayData;
}

@property(nonatomic,strong)UITableView *tableView;

@end

@implementation AccountViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavTitle:@"余额流水" titleColor:[UIColor blackColor] font:font17];
    self.tableView.backgroundColor = [UIColor whiteColor];
    [self loadingData];
}

- (void)loadingData{
    __weak typeof(self)weakself = self;
    [[PPHttpRequsetData shareInstance] requestStyle:Request_POST URL:@"/ShopApi/Finance/getMoneyList" parameter:@{} successBlock:^(PPHttpRequest *request, id responseObj) {
        _todayData = responseObj;
        [weakself.tableView reloadData];
    } failBlock:^(PPHttpRequest *request, NSString *errMsg) {
        [AlertUtils showToastWithMessage:errMsg inView:self.view hideAfterDelay:2.0 beIndeter:NO];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
   
}

- (UITableView *)tableView{
    if(_tableView == nil){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H-64) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerNib:[UINib nibWithNibName:@"AccountCell" bundle:nil] forCellReuseIdentifier:@"AccountCell"];
        //UITableView去掉自带系统的分割线
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self.view addSubview:_tableView];
    }
    return _tableView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _todayData.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dic = _todayData[indexPath.row];
    AccountCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccountCell" forIndexPath:indexPath];
    cell.accountTime.text = [ToolClass strToTime:dic[@"add_time"] format:@"yyyy-MM-dd HH:mm:ss"];
    cell.accountNumber.text = [NSString stringWithFormat:@"%@元",dic[@"money"]];
    cell.balance.text = [NSString stringWithFormat:@"余额：%@元",dic[@"money_sp"]];
    if([dic[@"type"] isEqualToString:@"1"]){
        cell.state.text = @"收入";
    }else if([dic[@"type"] isEqualToString:@"2"]){
        cell.state.text = @"平台服务费";
        
    }else if ([dic[@"type"] isEqualToString:@"3"]){
        cell.state.text = @"提现";
    }

    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 64;
}

@end
